package domain

type AuthorizationRole int64

func (a AuthorizationRole) And(ar AuthorizationRole) AuthorizationRole {
	return a & ar
}
func (a AuthorizationRole) Add(ar AuthorizationRole) AuthorizationRole {
	return a | ar
}
func (a AuthorizationRole) Has(ar AuthorizationRole) bool {
	return (a & ar) > 0
}

const (
	_           AuthorizationRole = 0
	AuthStudent AuthorizationRole = 1 << 0
	AuthLeader  AuthorizationRole = 1 << 1
	AuthAdmin   AuthorizationRole = 1 << 2
)

var (
	AuthKeyValue = map[AuthorizationRole]string{
		AuthStudent: "student",
		AuthLeader:  "leader",
		AuthAdmin:   "admin",
	}
)

const (
	UserActorFieldClub = "Club"
	UserActorFieldUser = "User"
)

type UserActor struct {
	ID     int64             `json:"id"`
	UserID int64             `json:"-" gorm:"not null"`
	ClubID *int64            `json:"-"`
	Role   AuthorizationRole `json:"role" gorm:"default:0"`
	Club   *Club             `json:"club" gorm:"foreignKey:ClubID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	User   User              `json:"user" gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}

type UserActorDTO struct {
	ID     int64    `json:"id"`
	UserID int64    `json:"-" gorm:"not null"`
	ClubID *int64   `json:"-"`
	Role   int64    `json:"role" gorm:"default:0"`
	Club   *ClubDTO `json:"club" gorm:"foreignKey:ClubID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	User   UserDTO  `json:"user" gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}
